package io.cici.cc.mybatis.lite.reflection.invoker;

import io.cici.cc.mybatis.lite.util.SecurityManagerUtil;

import java.lang.reflect.Field;


/**
 * @author huihui
 */
public class GetFieldInvoker implements Invoker {
    private final Field field;

    public GetFieldInvoker(Field field) {
        this.field = field;
    }

    @Override
    public Object invoke(Object target, Object[] args) throws IllegalAccessException {
        try {
            return field.get(target);
        } catch (IllegalAccessException e) {
            if (SecurityManagerUtil.memberAccessibleControl()) {
                field.setAccessible(true);
                return field.get(target);
            }
            throw e;
        }
    }

}
